//
//  MCMathUnits.m
//  TLYL
//
//  Created by miaocai on 2017/6/2.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMathUnits.h"
#import "MCStakeUntits.h"
#define Delete0Marr(arr,model) [MCMathUnits GetNumberWith:arr andModel:model]

@implementation MCMathUnits
#pragma mark-传入model 返回格式

+(MCPaySelectedCellModel *)GetFormatWithWFModel:(MCBasePWFModel *)WFmodel{
    
    MCPaySelectedCellModel * Pmodel =[[MCPaySelectedCellModel alloc]init];
    
    /**奖励金额*/
    NSString * bonus=[NSString stringWithFormat:@"%f",WFmodel.bonus];
    
    /**注数*/
    NSString * stakeNumber=[NSString stringWithFormat:@"%d",WFmodel.stakeNumber];
    
    /**倍数*/
    NSString * multiple=[NSString stringWithFormat:@"%d",WFmodel.multiple];
    
    /**购买金额*/
    NSString * payMoney=[NSString stringWithFormat:@"%f",WFmodel.payMoney];
    
    /**玩法名称*/
    NSString * WFName =[NSString stringWithFormat:@"%@_%@",WFmodel.typeName,WFmodel.name];
    
    /**拼接号码*/
    NSMutableArray * haoMaArry =[[NSMutableArray alloc]init];
    NSString * haoMa =@"";
    
    
    //单式
    if (WFmodel.danShiArray.count>0) {
        //11选5 PK10
        if ([WFmodel.lotteryCategories isEqualToString:@"esf"]||[WFmodel.lotteryCategories isEqualToString:@"pks"]) {
            
            for (NSString * string in WFmodel.danShiArray) {
                //01_02,03_04 -> 01|02_03|04
                NSString * str = [string stringByReplacingOccurrencesOfString:@" "withString:@"|"];
                [haoMaArry addObject:str];
                
                if ([haoMa isEqualToString:@""]) {
                    haoMa=str;
                }else{
                    haoMa=[NSString stringWithFormat:@"%@ %@",haoMa,str];
                }
            }
            
            //含有选项卡的
        }else if ([WFmodel.isShowSelectedCard isEqualToString:@"1"]){
            for (NSString * string in WFmodel.danShiArray) {
                //12_34 -> 1,2_3,4#千百十个
                NSArray * item= [MCMathUnits getArrWithStr:string];
                [haoMaArry addObject:[item componentsJoinedByString:@","]];
            }
            haoMa=[haoMaArry componentsJoinedByString:@" "];
            NSString * strCard=[MCMathUnits getSelectCardWithArr:WFmodel.selectedCardArray];
            haoMa=[NSString stringWithFormat:@"%@#%@",haoMa,strCard];
            
            //其他
        }else{
            for (NSString * string in WFmodel.danShiArray) {
                //12_34 -> 12_34
                [haoMaArry addObject:string];
            }
            haoMa=[haoMaArry componentsJoinedByString:@" "];
        }
        
        //胆拖
    }else if([WFmodel.isDanTuo integerValue]==1){
        
        NSMutableArray * DMArr=[[NSMutableArray alloc]init],*TMArr=[[NSMutableArray alloc]init];
        for (MCBaseSelectedModel * Smodel in WFmodel.baseSelectedModel) {
            //胆码
            if (Smodel.index==0) {
                DMArr=Smodel.selectedArray;
                //托码
            }else if (Smodel.index==1){
                TMArr=Smodel.selectedArray;
            }
        }
        NSString *DMHaoMa=@"";
        NSString *TMHaoMa=@"";
        for (NSString * str in DMArr) {
            if ([DMHaoMa isEqualToString:@""]) {
                DMHaoMa=str;
            }else{
                DMHaoMa=[NSString stringWithFormat:@"%@,%@",DMHaoMa,str];
            }
        }
        [haoMaArry addObject:DMHaoMa];
        for (NSString * str in TMArr) {
            if ([TMHaoMa isEqualToString:@""]) {
                TMHaoMa=str;
            }else{
                TMHaoMa=[NSString stringWithFormat:@"%@,%@",TMHaoMa,str];
            }
        }
        [haoMaArry addObject:TMHaoMa];
        
        haoMa=[NSString stringWithFormat:@"%@#%@",DMHaoMa,TMHaoMa];
        
        //定位胆
    }else if ([WFmodel.isDingWeiDan integerValue]==1){
        
        for (int i=0 ;i<[WFmodel.lineCount intValue];i++) {
            NSString * wei=@"*";
            for (MCBaseSelectedModel *Smodel in WFmodel.baseSelectedModel) {
                if (Smodel.index==i) {
                    wei = [Delete0Marr(Smodel.selectedArray ,WFmodel) componentsJoinedByString:@","];
                }
            }
            [haoMaArry addObject:wei];
        }
        haoMa=[haoMaArry componentsJoinedByString:@"|"];
        
        //其他
    }else{
        for (int i=0 ;i<[WFmodel.lineCount intValue];i++) {
            
            for (MCBaseSelectedModel *Smodel in WFmodel.baseSelectedModel) {
                if (Smodel.index==i) {
                    NSString * wei= [Delete0Marr(Smodel.selectedArray,WFmodel) componentsJoinedByString:@","];
                    [haoMaArry addObject:wei];
                }
            }
            
        }
        haoMa=[haoMaArry componentsJoinedByString:@"|"];
        //有选项卡
        if ([WFmodel.isShowSelectedCard isEqualToString:@"1"]) {
            NSString * strCard=[MCMathUnits getSelectCardWithArr:WFmodel.selectedCardArray];
            haoMa=[NSString stringWithFormat:@"%@#%@",haoMa,strCard];
        }
        
    }
    
    Pmodel.haoMa=haoMa;
    Pmodel.haoMaArry=haoMaArry;
    Pmodel.WFName=WFName;
    Pmodel.bonus=bonus;
    Pmodel.stakeNumber=stakeNumber;
    Pmodel.multiple=multiple;
    Pmodel.payMoney=payMoney;
    return Pmodel;
}

/*
 * 将数组@[@"01",@"02"]  ->@[@"1",@"2"]
 */
+(NSMutableArray *)GetNumberWith:(NSArray *)arr andModel:(MCBasePWFModel *)model{
    NSMutableArray * marr=[[NSMutableArray alloc]init];
    if ([model.lotteryCategories isEqualToString:@"esf"]||[model.lotteryCategories isEqualToString:@"pks"]) {
        marr= [NSMutableArray arrayWithArray:arr];
        return marr;
    }
    
    for (NSString * str in arr) {
        [marr addObject:[MCMathUnits getCwithStr:str]];
    }
    return marr;
}

/*
 * 去掉字符开头的0
 */
+(NSString * )getCwithStr:(NSString*)str{
    NSString *first = [str substringToIndex:1];//字符串开始
    if ([first isEqualToString:@"0"]&&str.length>1) {
        return [str substringFromIndex:str.length-1];
    }
    return str;
}
/*
 * 将字符串 转化成数组
 */
+(NSMutableArray *)getArrWithStr:(NSString *)str{
    NSMutableArray * marr=[[NSMutableArray alloc]init];
    for (int i=0; i<str.length; i++) {
        [marr addObject:[str substringWithRange:NSMakeRange(i, 1)]];
    }
    return marr;
}
/*
 * 选项卡 去掉“位”
 */
+(NSString *)getSelectCardWithArr:(NSArray *)arr{
    NSString * str=[arr componentsJoinedByString:@""];
    str=[str stringByReplacingOccurrencesOfString:@"位"withString:@""];
    return str;
}
@end








